<?php

namespace app\openapi;

use app\BaseController;

abstract class ApiBaseController extends BaseController
{
    public function jsonSuccess($msg = 'success', $data = [])
    {
        return json(['code' => 200, 'msg' => $msg, 'data' => $data]);
    }

    public function jsonError($msg = '', $data = [])
    {
        return json(['code' => -1, 'msg' => $msg, 'data' => $data]);
    }

    public function unauthorized($message, $code = 401, $data = [])
    {
        return json(['code' => $code, 'msg' => $message, 'data' => $data], $code);
    }

    public function forceUnauthorized($message, $code = 401, $data = [])
    {
        return json(['code' => $code, 'msg' => $message, 'data' => $data], $code)->cookie('refresh_token', '', -1);
    }
}